<template>
  <svg :class="svgClass" v-if="isSvgIcon()" aria-hidden="true">
    <use :xlink:href="iconName"/>
  </svg>
  <!--<span :class="spanClass"  v-else>
    <i :class="iconClass" v-else></i>
  </span>-->
  <i :class="iconClass + ' ' + className" v-else></i>
</template>

<script>
export default {
  name: 'Icon',
  props: {
    iconClass: {
      type: String,
      required: true,
      default: () => ''
    },
    className: {
      type: String,
      default: ''
    }
  },
  methods: {
    isSvgIcon() {
      if (this.iconClass) {
        return !this.iconClass.startsWith('el-icon')
      }
      return false
    }
  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`
    },
    svgClass() {
      if (this.className) {
        return `svg-icon ${this.className}`
      } else {
        return 'svg-icon'
      }
    },
    spanClass() {
      return `span-icon ${this.className}`
    }
  }
}
</script>

<style scoped>
  .svg-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
  }

</style>
